<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page isELIgnored="false"%>
<%@ include file="../common/taglibs.jsp"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!doctype html>
<html>
<head lang="zh-CN">
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="renderer" content="webkit">
<title>退货保证金管理</title>
<link rel="icon" href="favicon.ico" type="image/x-icon"/>
<!-- 当前页面样式 -->
<link rel="stylesheet" href="<s:url value="/css/common.css"/>"/>
<!-- 当前页面样式 END -->
<style type="text/css">
.blue{
	color: blue
}
</style>
<script type="text/javascript" src="<s:url value="/js/jquery-1.9.1.js" />"></script>
<script type="text/javascript" src="<s:url value="/js/My97DatePicker/WdatePicker.js"/>"></script>
<script type="text/javascript">
$(document).ready(function(){
		$('#sub').click(function(){
			$("#queryForm").attr("action","<%=basePath%>/margin/queryMargin.ct");
			$("#queryForm").submit();
			$(this).attr("disabled",true);
		});
		
});	

function addMargin(){
	window.location.href="<%=basePath%>/margin/addMargin.ct";
}


$(function(){
	/* 
		修改操作
	*/
	$(document).on("click", "#modify", function () {
        var tdArray = $(this).parent().prevAll();
        var securityMoney = tdArray.eq(2).text();
        tdArray.eq(2).html("<input  type='text' value='"+$.trim(securityMoney)+"' />");
        $(this).text("提交");
        $(this).attr("id","submitUpdate");
    });
	
	/* 
		提交操作
	*/
	 $(document).on("click", "#submitUpdate", function () {
		var tdArray = $(this).parent().prevAll();
        var securityAmt = $.trim(tdArray.eq(2).find("input").val());
        var mchtCd = $.trim(tdArray.eq(4).text());
        
        if(mchtCd == null || mchtCd == ""){
    		alert("商户号不能为空");
    		return false;
    	}
        
        if(!/^[0-9]*[1-9][0-9]*$/.test(securityAmt)){
    		alert("保证金总金额输入不规范");
    		return false;
    	}
    		
    	/* if(parseFloat(securityAmt).toString() == "NaN"){
    		alert("保证金总金额输入不规范");
    		return false;
    	}
    	
    	if(securityAmt.lastIndexOf(".") != -1 && securityAmt.substring(securityAmt.indexOf(".")+1).length >2){
        	alert("保证金总额最多只能保留两位小数");
        	return false;
        } */
        
       
        
        if(confirm("确认将商户【"+mchtCd+"】的保证金总额修改为【"+securityAmt+"】元？")){
        	
        	$(this).attr("id","");
        	
        	$.ajax({
            	type:"post",
            	url:"updateMarginSubmit.ct",
                data:{"mchtCd":mchtCd,"securityAmt":securityAmt}, 
            	dataType:"json",
            	success:function(result){
            		alert(result.res.msg);
            		$('#sub').click();
            		
            	},error:function(){
            		
            	}
            	
            });
        }
        
    }); 
	
	/* 查询明细操作  */
	 $(document).on("click", "#details", function () {
	        var tdArray = $(this).parent().prevAll();
	        var mchtCd = $.trim(tdArray.eq(5).text());
	        window.location.href="<%=basePath%>/margin/queryMarginAndReturnDetails.ct?details="+mchtCd;
	        
	    });
	
})
	
	
</script>
</head>

<body>
		<s:form id="queryForm" action="" method="post"
			theme="simple">
			<table class="tb">
				<tbody>
				<tr class="tb-line">
            		<td class="tb-td" colspan="4"><div class="tb-h2">POS收单运营管理平台</div></td>
        		</tr>
				 <tr class="tb-line">
					<td class="tb-td" colspan="4">
						<div class="tb-h3">退货保证金管理</div>
					</td>
				</tr>

				 <tr class="tb-line">
				 	<td width="12%" style="min-width: 150px" align="right" class="tb-td">
				 	 <div class="tb-h4">商户号</div>
				 	 </td>
					<td class="tb-td">
                		<label class="tb-input-normal">
						<s:textfield  name="searchCondition.mchntCd" cssClass="queryWidth" />
							</label>
					</td>
					
				</tr>
				
				<tr>
						<td colspan="4" align="center"><span style="color: red"><s:actionerror /></span>
							<span style="color: red;"><s:actionmessage /></span > <span style="color: red;"><s:fielderror
									cssClass="fieldError" /></span>
							<span id="otherError"></span>
						</td>
					</tr>
				 <tr class="tb-line">
           		 <td class="tb-td line-submit" align="right" colspan="4">
                <label class="tb-input-submit"><input type="button" value="查询" id="sub"/></label>
                <s:if test="#session.session_merchant.roleType==\"06\" || #session.session_merchant.roleType==\"07\"">
                	<label class="tb-input-submit"><input type="button" value="添加" id="add" onclick="addMargin()"/></label>
                </s:if>
				<label class="tb-input-submit"><s:reset value="取 消" /></label> 
					 
				</td>
				</tr>
				
				<s:if 	test="#request.searchRsList != null && #request.searchRsList.size>0">
					<tr class="tb-line">
						<td class="tb-td paging" colspan="4"><page:pageCount
								max_pages="11" totalPage="${requestScope.totalPage}"
								currentPage="${requestScope.currentPage}"
								action="${rootPath}/margin/queryMargin.ct?currentPage=" />

						</td>
					</tr>
				</s:if>
			</table>
	</s:form>		
				
	<div class="big-tb">
    <table class="tb" style="width: 100%;">
				<thead>
            	<tr class="tb-line">
                <th class="tb-th" colspan="7"><div class="tb-h3">退货保证金列表</div></th>
            	</tr>
					 <tr class="tb-line bg-gray">
					 					 	
						<th class="tb-th">机构号</th>
						<th class="tb-th">商户号</th>
						<th class="tb-th">商户名称</th>
						<th class="tb-th">终端号</th>
						<th class="tb-th">保证金总金额</th>
						<th class="tb-th">剩余可退货金额</th>
						<th class="tb-th">已退货总金额</th>				
						<s:if test="#session.session_merchant.roleType==\"06\" || #session.session_merchant.roleType==\"07\"">
						<th class="tb-th">操作</th>
						 </s:if> 
					</tr>
				</thead>
				<tbody>
					<s:iterator value="#request.searchRsList" status="stat" id="bean">
							<tr class="tb-line" >							
														
							<td class="tb-td"><s:property value="#bean.insIdCd"/></td>
							<td class="tb-td"><s:property value="#bean.mchntCd"/></td>
							<td class="tb-td"><s:property value="#bean.name"/></td>
							<td class="tb-td"><s:property value="#bean.termId"/></td>
							<td class="tb-td"><s:property value="#bean.securityAmt"/></td>
							<td class="tb-td"><s:property value="#bean.currentAmt"/></td>
							<td class="tb-td"><s:property value="#bean.backAmt"/></td>
							<s:if test="#session.session_merchant.roleType==\"06\" || #session.session_merchant.roleType==\"07\"">
							<td align="center">
							<a id="modify" class="blue">修改</a>
							<a id="details" class="blue">明细</a>
							</td>
							</s:if>
						</s:iterator>
						 
				</tbody>
			</table>
			</div>
		
	
</body>
</html>
